#include "localstoragewidget.h"

LocalStorageWidget::LocalStorageWidget(QWidget *parent) :
    QWidget(parent)
{
    QVBoxLayout *centralLayout = new QVBoxLayout();
    this->setLayout(centralLayout);

    QHBoxLayout *pathLayout = new QHBoxLayout();
    centralLayout->addLayout(pathLayout);

    QLabel *pathLabel = new QLabel(tr("Target: "));
    pathLayout->addWidget(pathLabel);

    pathValue = new QLineEdit();
    pathLayout->addWidget(pathValue);

    QPushButton *pathButton = new QPushButton(tr("..."));
    pathLayout->addWidget(pathButton);
    connect(pathButton, SIGNAL(clicked()), this, SLOT(pathButtonClicked()));
}

QString LocalStorageWidget::getTargetPath()
{
    return pathValue->text();
}

void LocalStorageWidget::pathButtonClicked()
{
    QFileDialog dialog(this, tr("Select directory for backup..."));
    dialog.setFileMode(QFileDialog::DirectoryOnly);
    if(dialog.exec() == QFileDialog::Accepted)
    {
        pathValue->setText(dialog.selectedFiles().first());
    }
}
